%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Paper, to be run with knitr
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{sansmathaccent} 
\usepackage{dcolumn}
\usepackage{colortbl, xcolor}
\pdfmapfile{+sansmathaccent.map}
\providecommand{\keywords}[1]{\textbf{\textit{Key words:}} #1}
\providecommand{\jel}[1]{\textbf{\textit{JEL Codes: }} #1}
\begin{document}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

<<setup-paper, include=FALSE>>=
opts_chunk$set(echo=FALSE, cache=TRUE, warning=FALSE, message=FALSE, tidy=FALSE, dev="tikz")
require("knitr")
require("tikzDevice")
require(foreign)
require(ggplot2)
require(reshape2)
require(lfe)
require(lubridate)
require("tidyr")
require("modelr")
require("broom")
require(stargazer)
require(dplyr)
require(rlang)
require(purrr)
require("texreg")
require("gtools")
require("np")
require(mgcv)
require("AER")
require("BSDA")
require("stargazer")
require("remotes")

require(vtable)


require(sjPlot)
require(sjlabelled)
require(sjmisc)
require(car)

require(data.table)
require(xtable)
require("qwraps2")
require(doBy)
require("magrittr")
#install.packages("gridExtra")
library(gridExtra)

`%notin%` <- Negate(`%in%`)
setwd("/Users/Mema 1/Dropbox/AidDataGender/July 2021")
Sys.setlocale(category = "LC_ALL", locale = "en_GB.UTF-8")

options(scipen = 3, digits = 3)
@


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Title
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{Aid and Gender\\ \sc{\small Tables}}

\author{Maria Perrotta Berlin\thanks{SITE, Stockholm School of Economics.} }


\maketitle

\begin{abstract}



\noindent
\keywords{ }
\noindent
\jel{}

%\center{PRELIMINARY, DO NOT CITE.}



\end{abstract}

% full sample (including urban)

<<BaseU, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
# created in Malawi2021.r


dhs$genderind <- dhs$wattind
dhs[is.na(dhs$wattind), "genderind"] <- dhs[is.na(dhs$wattind), "mattind"]
d <- as.data.frame(cor(dhs[,c( "genderind", "empind", "agencyind")], use = "complete.obs"))
#d[is.na(d)] <- 0
index.mat <- data.frame(chol2inv(chol(d)))
dhs$index <- rowSums(t(apply(dhs[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))


robse <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 2]) }
robp <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 4]) }

HSbase <- felm(empind ~ I(Exposure10N>0)*After , dhs)
HSbaseC <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase <- felm(agencyind ~ I(Exposure10N>0)*After , dhs)
JbaseC <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase <- felm(wattind ~ I(Exposure10N>0)*After , dhs)
WIbaseC <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase <- felm(mattind ~ I(Exposure10N>0)*After , dhs)
MIbaseC <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase <- felm(index ~ I(Exposure10N>0)*After , dhs)
IbaseC <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


star.out.1 <- stargazer(HSbase, Jbase, WIbase,  MIbase,  Ibase,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbase), robse(Jbase), robse(WIbase), robse(MIbase), robse(Ibase)), 
         #p= list(robp(HSbase), robp(Jbase), robp(WIbase), robp(MIbase), robp(Ibase)), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, all aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:Replication",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          )

star.out.2 <- stargazer(HSbaseC, JbaseC, WIbaseC,  MIbaseC,  IbaseC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbaseC), robse(JbaseC), robse(WIbaseC), robse(MIbaseC), robse(IbaseC)), 
         #p= list(robp(HSbaseC), robp(JbaseC), robp(WIbaseC), robp(MIbaseC), robp(IbaseC)), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, and the number of aid projects at the district level. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )


@

 
<<BaseGU, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  

HSbaseG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
HSbaseGC <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
JbaseG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
JbaseGC <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbaseG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
WIbaseGC <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbaseG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
MIbaseGC <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
IbaseG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
IbaseGC <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)

star.out.1 <- stargazer(HSbaseG, JbaseG, WIbaseG,  MIbaseG,  IbaseG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, gender aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:gender",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove")
          )

star.out.2 <- stargazer(HSbaseGC, JbaseGC, WIbaseGC,  MIbaseGC,  IbaseGC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@

%Base

<<Base, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
# created in Malawi2021.r

dhs.urban <- dhs
dhs <- dhs[dhs$urban==0,]

dhs$genderind <- dhs$wattind
dhs[is.na(dhs$wattind), "genderind"] <- dhs[is.na(dhs$wattind), "mattind"]
d <- as.data.frame(cor(dhs[,c( "genderind", "empind", "agencyind")], use = "complete.obs"))
#d[is.na(d)] <- 0
index.mat <- data.frame(chol2inv(chol(d)))
dhs$index <- rowSums(t(apply(dhs[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))


#dhs$index2 <-rowMeans(dhs[,c("genderind", "empind", "agencyind")], na.rm=TRUE)

#dhs$index3 <-rowMeans(dhs[,c("genderind", "empind", "agencyind")])

robse <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 2]) }
robp <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 4]) }

HSbase <- felm(empind ~ I(Exposure10N>0)*After , dhs)
HSbaseC <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase <- felm(agencyind ~ I(Exposure10N>0)*After , dhs)
JbaseC <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase <- felm(wattind ~ I(Exposure10N>0)*After , dhs)
WIbaseC <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase <- felm(mattind ~ I(Exposure10N>0)*After , dhs)
MIbaseC <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase <- felm(index ~ I(Exposure10N>0)*After , dhs)
IbaseC <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


star.out.1 <- stargazer(HSbase, Jbase, WIbase,  MIbase,  Ibase,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbase), robse(Jbase), robse(WIbase), robse(MIbase), robse(Ibase)), 
         #p= list(robp(HSbase), robp(Jbase), robp(WIbase), robp(MIbase), robp(Ibase)), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, all aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:Replication",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          )

star.out.2 <- stargazer(HSbaseC, JbaseC, WIbaseC,  MIbaseC,  IbaseC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbaseC), robse(JbaseC), robse(WIbaseC), robse(MIbaseC), robse(IbaseC)), 
         #p= list(robp(HSbaseC), robp(JbaseC), robp(WIbaseC), robp(MIbaseC), robp(IbaseC)), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, and the number of aid projects at the district level. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )


@

 
<<BaseG, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  

HSbaseG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
HSbaseGC <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
JbaseG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
JbaseGC <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbaseG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
WIbaseGC <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbaseG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
MIbaseGC <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
IbaseG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After , dhs)
IbaseGC <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)

star.out.1 <- stargazer(HSbaseG, JbaseG, WIbaseG,  MIbaseG,  IbaseG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, gender aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:gender",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove")
          )

star.out.2 <- stargazer(HSbaseGC, JbaseGC, WIbaseGC,  MIbaseGC,  IbaseGC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@



%projekt inom 25 km; 

<<Robustness25, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
#load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
HSbase25C <- felm(empind ~ I(Exposure25N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase25C <- felm(agencyind ~ I(Exposure25N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase25C <- felm(wattind ~ I(Exposure25N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase25C <- felm(mattind ~ I(Exposure25N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase25C <- felm(index ~ I(Exposure25N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


stargazer(HSbase25C, Jbase25C, WIbase25C,  MIbase25C,  Ibase25C,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact within 25 km",
          label = "tab:Robustness25",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure25N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

HSbase25G <- felm(empind ~ I(Exposure25GN>0)*After+ Exposure25N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase25G <- felm(agencyind ~ I(Exposure25GN>0)*After+ Exposure25N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase25G <- felm(wattind ~ I(Exposure25GN>0)*After+ Exposure25N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase25G <- felm(mattind ~ I(Exposure25GN>0)*After+ Exposure25N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase25G <- felm(index ~ I(Exposure25GN>0)*After+ Exposure25N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


stargazer(HSbase25G, Jbase25G, WIbase25G,  MIbase25G,  Ibase25G,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          dep.var.caption  = "Panel B: Gender aid",
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.8\\textwidth}{Exposure is measured within a 25 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure25GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@



%projekt inom 5 år; 

<<Replication5y, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  


HSbase5C <- felm(empind ~ I(Exposure10Ny5>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase5C <- felm(agencyind ~ I(Exposure10Ny5>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase5C <- felm(wattind ~ I(Exposure10Ny5>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase5C <- felm(mattind ~ I(Exposure10Ny5>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase5C <- felm(index ~ I(Exposure10Ny5>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


stargazer(HSbase5C, Jbase5C, WIbase5C,  MIbase5C,  Ibase5C,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact of projects within 5 years",
          label = "tab:Robustness5",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure10Ny5\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

HSbase5G <- felm(empind ~ I(Exposure10GNy5>0)*After+ Exposure10Ny5*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase5G <- felm(agencyind ~ I(Exposure10GNy5>0)*After+ Exposure10Ny5*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase5G <- felm(wattind ~ I(Exposure10GNy5>0)*After+ Exposure10Ny5*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase5G <- felm(mattind ~ I(Exposure10GNy5>0)*After+ Exposure10Ny5*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase5G <- felm(index ~ I(Exposure10GNy5>0)*After+ Exposure10Ny5*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


stargazer(HSbase5G, Jbase5G, WIbase5G,  MIbase5G,  Ibase5G,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          dep.var.caption  = "Panel B: Gender aid",
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.8\\textwidth}{Exposure is measured within a 10 km radius, up to 5 years prior or following the survey interview. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GNy5\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@

%projekt inom 20 km; 

<<Robustness20, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  


HSbase20C <- felm(empind ~ I(Exposure20N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase20C <- felm(agencyind ~ I(Exposure20N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase20C <- felm(wattind ~ I(Exposure20N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase20C <- felm(mattind ~ I(Exposure20N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase20C <- felm(index ~ I(Exposure20N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


stargazer(HSbase20C, Jbase20C, WIbase20C,  MIbase20C,  Ibase20C,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact within 20 km",
          label = "tab:Robustness20",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure20N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

HSbase20G <- felm(empind ~ I(Exposure20GN>0)*After+ Exposure20N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase20G <- felm(agencyind ~ I(Exposure20GN>0)*After+ Exposure20N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase20G <- felm(wattind ~ I(Exposure20GN>0)*After+ Exposure20N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase20G <- felm(mattind ~ I(Exposure20GN>0)*After+ Exposure20N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase20G <- felm(index ~ I(Exposure20GN>0)*After+ Exposure20N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


stargazer(HSbase20G, Jbase20G, WIbase20G,  MIbase20G,  Ibase20G,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          dep.var.caption  = "Panel B: Gender aid",
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.8\\textwidth}{Exposure is measured within a 20 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure20GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@


% Matrilineal vs patrilineal areas

<<MatriNew, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
temp <- aggregate(dhs[, "matrilineal"], list(dhs$grid, dhs$DHSCLUST), mean)
colnames(temp) <- c("grid", "DHSCLUST", "sh.matri")
dhs <- merge(dhs, temp, by=c("grid", "DHSCLUST"), all=T)

HSMatri <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
JMatri <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
WIMatri <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
MIMatri <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
IMatri <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)

HSMatriG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
JMatriG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
WIMatriG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
MIMatriG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)
IMatriG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.73)

stargazer(HSMatri, JMatri, WIMatri,  MIMatri,  IMatri,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact in matrilineal areas",
          label = "tab:Matri",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

stargazer(HSMatriG, JMatriG, WIMatriG,  MIMatriG,  IMatriG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE,
          omit.stat = c("adj.rsq", "ser"),
          dep.var.caption  = "Panel B: Gender aid",
          notes        = "\\parbox[t]{.85\\textwidth}{Exposure is measured within a 10 km radius. Ethnic groups classified as matrilineal are: Chewa, Lomwe, Yao, Ngoni, and Nyanja, based on Ibik (1970). HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.73, "index"], na.rm=T),3)))
          )

@

 <<PatriNew, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  

HSPatri <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
JPatri <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
WIPatriC <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
MIPatriC <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
IPatriC <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)

HSPatriG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
JPatriG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
WIPatriG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
MIPatriG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)
IPatriG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.73)

stargazer(HSPatri, JPatri, WIPatriC,  MIPatriC,  IPatriC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          
          #se= list(robse(HSPatri), robse(JPatri), robse(WIPatriC), robse(MIPatriC), robse(IPatriC)), 
         #p= list(robp(HSPatri), robp(JPatri), robp(WIPatriC), robp(MIPatriC), robp(IPatriC)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact in patrilineal areas",
          label = "tab:Patri",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

stargazer(HSPatriG, JPatriG, WIPatriG,  MIPatriG,  IPatriG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          #se= list(robse(HSPatriG), robse(JPatriG), robse(WIPatriG), robse(MIPatriG), robse(IPatriG)), 
         #p= list(robp(HSPatriG), robp(JPatriG), robp(WIPatriG), robp(MIPatriG), robp(IPatriG)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE,
          omit.stat = c("adj.rsq", "ser"),
          dep.var.caption  = "Panel B: Gender aid",
          notes        = "\\parbox[t]{.85\\textwidth}{Exposure is measured within a 10 km radius. Ethnic groups classified as matrilineal are: Chewa, Lomwe, Yao, Ngoni, and Nyanja, based on Ibik (1970). HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.73, "index"], na.rm=T),3)))
          )

@





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Baseline specification for 2000-2004
<<Basepre, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
dhs.pre.urban <- dhs.pre
dhs.pre <- dhs.pre[dhs.pre$urban==0,]

dhs.pre$Exposure <- 0
dhs.pre[dhs.pre$Exposure10N>0 & !is.na(dhs.pre$Exposure10N), "Exposure"] <- 1
dhs.pre[is.na(dhs.pre$Exposure10N), "Exposure"] <- NA

dhs.pre$genderind <- dhs.pre$wattind
dhs.pre[is.na(dhs.pre$wattind), "genderind"] <- dhs.pre[is.na(dhs.pre$wattind), "mattind"]

dhs.pre$index <- rowSums(t(apply(dhs.pre[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))


#dhs.pre$index2 <-rowMeans(dhs.pre[,c("genderind", "empind", "agencyind")], na.rm=TRUE)

#dhs.pre$index3 <-rowMeans(dhs.pre[,c("genderind", "empind", "agencyind")])

HSbasepre <- felm(empind ~ Exposure*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
Jbasepre <- felm(agencyind ~ Exposure*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
WIbasepre <- felm(wattind ~ Exposure*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
MIbasepre <- felm(mattind ~ Exposure*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
Ibasepre <- felm(index ~ Exposure*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid|0| DHSCLUST, dhs.pre)


stargazer(HSbasepre, Jbasepre, WIbasepre,  MIbasepre,  Ibasepre,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          
          #se= list(robse(HSbasepre), robse(Jbasepre), robse(WIbasepre), robse(MIbasepre), robse(Ibasepre)), 
         #p= list(robp(HSbasepre), robp(Jbasepre), robp(WIbasepre), robp(MIbasepre), robp(Ibasepre)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Pre-trends",
          label = "tab:pretrends",
          omit.stat = c("adj.rsq", "ser"),
          #keep = c("\\Exposure\\", "After")
          keep = c("Exposure", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

dhs.pre$ExposureG <- 0
dhs.pre[dhs.pre$Exposure10GN>0 & !is.na(dhs.pre$Exposure10GN), "ExposureG"] <- 1
dhs.pre[is.na(dhs.pre$Exposure10GN), "ExposureG"] <- NA

HSbasepreG <- felm(empind ~ ExposureG*After+ Exposure10N*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
JbasepreG <- felm(agencyind ~ ExposureG*After+ Exposure10N*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
WIbasepreG <- felm(wattind ~ ExposureG*After+ Exposure10N*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
MIbasepreG <- felm(mattind ~ ExposureG*After+ Exposure10N*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
IbasepreG <- felm(index ~ ExposureG*After+ Exposure10N*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid|0 | DHSCLUST, dhs.pre)


stargazer(HSbasepreG, JbasepreG, WIbasepreG,  MIbasepreG,  IbasepreG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbasepreG), robse(JbasepreG), robse(WIbasepreG), robse(MIbasepreG), robse(IbasepreG)), 
         #p= list(robp(HSbasepreG), robp(JbasepreG), robp(WIbasepreG), robp(MIbasepreG), robp(IbasepreG)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          dep.var.caption  = "Panel B: Gender aid",
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.8\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          #keep = c("\\Exposure\\b", "After"),
          keep = c("ExposureG", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(mean(dhs.pre[dhs.pre$Year==2004, "empind"], na.rm=T),3), round(mean(dhs.pre[dhs.pre$Year==2004, "agencyind"], na.rm=T),3), round(mean(dhs.pre[dhs.pre$Year==2004, "wattind"], na.rm=T),3), round(mean(dhs.pre[dhs.pre$Year==2004, "mattind"], na.rm=T),3), round(mean(dhs.pre[dhs.pre$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs.pre[dhs.pre$Year==2004, "empind"], na.rm=T),3), round(sd(dhs.pre[dhs.pre$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs.pre[dhs.pre$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs.pre[dhs.pre$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs.pre[dhs.pre$Year==2004, "index"], na.rm=T),3)))
          )

@

% base in grid panel

<<gridpanel, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  

robse <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 2]) }
robp <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 4]) }

temp <- dhs %>% count(grid, DHSCLUST, v002)
temp<-temp %>% add_count(grid, DHSCLUST, name = "hh_n")
dhs <- merge(dhs, temp, by=c("grid", "DHSCLUST", "v002"), all=T)


grid.panel <- summaryBy(HhdSize+ age+ muslim+ matrilineal+  Exposure10N + YearsEdu+ Literacy+ OK2BeatWife+ distint+ index+ agencyind+ empind+ wattind+ mattind+ hh_n + Exposure10N+ Exposure10GN+ethnicity~ grid+After, FUN=c(mean), data=dhs, na.rm=T)

colnames(grid.panel)[3:20] <- c("HhdSize", "age", "muslim", "matrilineal", " Exposure10N ", "YearsEdu", "Literacy", "OK2BeatWife", "distint", "index", "agencyind", "empind", "wattind", "mattind", "hh_n", "Exposure10N", "Exposure10GN", "ethnicity")

HSbaseGrid <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
JbaseGrid <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
WIbaseGrid <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
MIbaseGrid <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
IbaseGrid <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)

HSbaseGridG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
JbaseGridG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
WIbaseGridG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
MIbaseGridG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)
IbaseGridG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+ethnicity|grid , grid.panel)

stargazer(HSbaseGrid, JbaseGrid, WIbaseGrid,  MIbaseGrid,  IbaseGrid,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         se = list(robse(HSbaseGrid), robse(JbaseGrid), robse(WIbaseGrid), robse(MIbaseGrid), robse(IbaseGrid)), 
          p = list(robp(HSbaseGrid), robp(JbaseGrid), robp(WIbaseGrid), robp(MIbaseGrid), robp(IbaseGrid)),  
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact in a balanced grid-cell panel",
          label = "tab:Matri",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

stargazer(HSbaseGridG, JbaseGridG, WIbaseGridG,  MIbaseGridG,  IbaseGridG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         se = list(robse(HSbaseGridG), robse(JbaseGridG), robse(WIbaseGridG), robse(MIbaseGridG), robse(IbaseGridG)), 
          p = list(robp(HSbaseGridG), robp(JbaseGridG), robp(WIbaseGridG), robp(MIbaseGridG), robp(IbaseGridG)), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE,
          omit.stat = c("adj.rsq", "ser"),
          dep.var.caption  = "Panel B: Gender aid",
          notes        = "\\parbox[t]{.85\\textwidth}{Exposure is measured within a 10 km radius. Ethnic groups classified as matrilineal are: Chewa, Lomwe, Yao, Ngoni, and Nyanja, based on Ibik (1970). HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Robust standard errors in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(grid.panel[grid.panel$After==0 , "empind"], na.rm=T),3), round(median(grid.panel[grid.panel$After==0 , "agencyind"], na.rm=T),3), round(median(grid.panel[grid.panel$After==0 , "wattind"], na.rm=T),3), round(median(grid.panel[grid.panel$After==0 , "mattind"], na.rm=T),3), round(median(grid.panel[grid.panel$After==0 , "index"], na.rm=T),3)),
            c("sd", round(sd(grid.panel[grid.panel$After==0 , "empind"], na.rm=T),3), round(sd(grid.panel[grid.panel$After==0 , "agencyind"], na.rm=T),3), round(sd(grid.panel[grid.panel$After==0 , "wattind"], na.rm=T),3), round(sd(grid.panel[grid.panel$After==0 , "mattind"], na.rm=T),3), round(sd(grid.panel[grid.panel$After==0 , "index"], na.rm=T),3)))
          )

@

%%%%%%%%%%%%%%%%%%%% Appendix %%%%%%%%%%%%%%%%%%%%

<<nordiffNew, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=
# Normalized differences - Pretreat
treat <- na.omit(dhs[dhs$Exposure10N>0 & dhs$After==0, c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "OK2BeatWife", "index") ]) 
control <- na.omit(dhs[dhs$Exposure10N==0 & dhs$After==0, c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "OK2BeatWife", "index") ])
data <-  na.omit(dhs[dhs$After==0 , c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "OK2BeatWife", "index", "After") ])
sumstatT <- do.call(data.frame,
                    list(meant = apply(treat, 2, mean, na.rm = T),
                        sdt = apply(treat, 2, sd, na.rm = T),
                        meanc = apply(control, 2, mean, na.rm = T),
                        sdc = apply(control, 2, sd, na.rm = T)))
                        # ,
                        # nd= apply(data[,-1], 2, 
                        # function(x) ((mean(x[data$Exposure10N>0], na.rm=T)-mean(x[data$Exposure10N==0], na.rm=T))/
                        #   ((sum((x[data$Exposure10N>0] - mean(x[data$Exposure10N>0], na.rm=T))^2, na.rm=T)/(nrow(treat)-1) +
                        #               sum((x[data$Exposure10N==0] - mean(x[data$Exposure10N==0], na.rm=T))^2, na.rm=T)/(nrow(control)-1))/2)^.5))))
                                                     
sumstatT$nd <- (sumstatT$meant-sumstatT$meanc)/((sumstatT$sdt^2+sumstatT$sdc^2)/2)^.5


table_nd <- xtable(sumstatT, auto = TRUE, booktabs=TRUE,  caption = "Normalized differences, pre-treatment", digit=2, include.rownames = FALSE, label='norrdiffNew')
colnames(table_nd)<-c("Mean T", "sd T", "Mean C", "sd C" ,"Nor Dif")

print(table_nd, floating = T, latex.environments = "center", table.placement="h")
#index
mean(data[data$Exposure10N>0, "index"], na.rm=T)
mean(data[data$Exposure10N==0, "index"], na.rm=T)
sum((data[data$Exposure10N>0, "index"] - mean(data[data$Exposure10N>0, "index"], na.rm=T))^2, na.rm=T)/nrow(treat)
sum((data[data$Exposure10N==0, "index"] - mean(data[data$Exposure10N==0, "index"], na.rm=T))^2, na.rm=T)/nrow(control)
(0.144-0.141)/(0.0538+0.0515)^.5
# 0.11
@

<<nordiffT, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=
# Normalized differences - Treatment groups
treat <- na.omit(dhs[dhs$Exposure10N>0 & dhs$After==1, c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "OK2BeatWife", "index") ]) 
control <- na.omit(dhs[dhs$Exposure10N>0 & dhs$After==0, c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "OK2BeatWife", "index") ])
data <-  na.omit(dhs[dhs$Exposure10N>0 , c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "OK2BeatWife", "index", "After") ])
sumstatT <- do.call(data.frame,
                    list(meant = apply(treat, 2, mean, na.rm = T),
                        sdt = apply(treat, 2, sd, na.rm = T),
                        meanc = apply(control, 2, mean, na.rm = T),
                        sdc = apply(control, 2, sd, na.rm = T)))
                        # ,
                        # nd= apply(data[,-1], 2, 
                        # function(x) ((mean(x[data$After==1], na.rm=T)-mean(x[data$After==0], na.rm=T))/
                        #   ((sum((x[data$After==1] - mean(x[data$After==1], na.rm=T))^2, na.rm=T)/(nrow(treat)-1) +
                        #               sum((x[data$After==0] - mean(x[data$After==0], na.rm=T))^2, na.rm=T)/(nrow(control)-1))/2)^.5))))
                                                     
sumstatT$nd <- (sumstatT$meant-sumstatT$meanc)/((sumstatT$sdt^2+sumstatT$sdc^2)/2)^.5


table_nd <- xtable(sumstatT, auto = TRUE, booktabs=TRUE,  caption = "Normalized differences", digit=2, include.rownames = FALSE, label='norrdiff')
colnames(table_nd)<-c("Mean 2010", "sd 2010", "Mean 2004", "sd 2004" ,"Nor Dif")

print(table_nd, floating = T, latex.environments = "center", table.placement="h")
#index
mean(data[data$After==1, "index"], na.rm=T)
mean(data[data$After==0, "index"], na.rm=T)
sum((data[data$After==1, "index"] - mean(data[data$After==1, "index"], na.rm=T))^2, na.rm=T)/nrow(treat)
sum((data[data$After==0, "index"] - mean(data[data$After==0, "index"], na.rm=T))^2, na.rm=T)/nrow(control)
(0.1770137-0.1437325)/(0.04122445+0.05380818)^.5
# 0.11
@

<<nordiffC, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=
# Normalized differences - Control groups
treat <- na.omit(dhs[dhs$Exposure10N==0 & dhs$After==1, c("HhdSize", "age", "muslim", "matrilineal",   "YearsEdu", "Literacy", "OK2BeatWife", "index") ]) 
control <- na.omit(dhs[dhs$Exposure10N==0 & dhs$After==0, c("HhdSize", "age", "muslim", "matrilineal",   "YearsEdu", "Literacy", "OK2BeatWife", "index") ])
data <-  na.omit(dhs[dhs$Exposure10N==0 , c("HhdSize", "age", "muslim", "matrilineal",   "YearsEdu", "Literacy", "OK2BeatWife", "index", "After") ])
sumstatT <- do.call(data.frame,
                    list(meant = apply(treat, 2, mean, na.rm = T),
                         sdt = apply(treat, 2, sd, na.rm = T),
                         meanc = apply(control, 2, mean, na.rm = T),
                         sdc = apply(control, 2, sd, na.rm = T)))
# ,
#                          nd= apply(data[,-1], 2, 
#                                    function(x) ((mean(x[data$After==1], na.rm=T)-mean(x[data$After==0], na.rm=T))/
#                                                   ((sum((x[data$After==1] - mean(x[data$After==1], na.rm=T))^2, na.rm=T)/(nrow(treat)-1) +
#                                                       sum((x[data$After==0] - mean(x[data$After==0], na.rm=T))^2, na.rm=T)/(nrow(control)-1))/2)^.5))))

sumstatT$nd <- (sumstatT$meant-sumstatT$meanc)/((sumstatT$sdt^2+sumstatT$sdc^2)/2)^.5

table_nd <- xtable(sumstatT, auto = TRUE, booktabs=TRUE,  caption = "Normalized differences - Control groups", digit=2, include.rownames = FALSE, label='norrdiff')
colnames(table_nd)<-c("Mean 2010", "sd 2010", "Mean 2004", "sd 2004" ,"Nor Dif")

print(table_nd, floating = T, latex.environments = "center", table.placement="h")

#matrilineal
mean(data[data$After==1, "matrilineal"], na.rm=T)
mean(data[data$After==0, "matrilineal"], na.rm=T)
sum((data[data$After==1, "matrilineal"] - mean(data[data$After==1, "matrilineal"], na.rm=T))^2, na.rm=T)/nrow(treat)
sum((data[data$After==0, "matrilineal"] - mean(data[data$After==0, "matrilineal"], na.rm=T))^2, na.rm=T)/nrow(control)
(0.6283022-0.7659496)/(0.2335385+0.1792708)^.5
#-0.21
#index
mean(data[data$After==1, "index"], na.rm=T)
mean(data[data$After==0, "index"], na.rm=T)
sum((data[data$After==1, "index"] - mean(data[data$After==1, "index"], na.rm=T))^2, na.rm=T)/nrow(treat)
sum((data[data$After==0, "index"] - mean(data[data$After==0, "index"], na.rm=T))^2, na.rm=T)/nrow(control)
(0.1680705-0.1411149)/(0.03979409+0.05149114)^.5
# 0.08921723
@

% Robustness %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Table of sectoral distribution
<<sector, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
library(plyr)
library(dplyr)

pr <- dataMalawi[dataMalawi$Precision<=2, ]
pr.sector1 <- pr %>%                              
group_by(AMP.Sector) %>%
summarise(count = n_distinct(Project.ID))
colnames(pr.sector1)[1]<-"Sector"
committments2 <- aggregate(x=pr$Comulative.Commitment,
          by=list(pr$AMP.Sector,pr$Project.ID),
          FUN=mean)
pr.sector2 <- committments2 %>%                              
group_by(Group.1) %>%
summarise(total = sum(x, na.rm=T))
pr.sector2$share=round(pr.sector2$total/sum(pr.sector2$total)*100,1)
colnames(pr.sector2)[1]<-"Sector"
pr.sector1 <- merge(pr.sector1, pr.sector2)
colnames(pr.sector1) <- c("Sector", "Count","Total", "Share")

bs <- dataMalawi[dataMalawi$Precision==8, ]
bs.sector1 <- bs %>%                              
group_by(AMP.Sector) %>%
summarise(count = n_distinct(Project.ID))
colnames(bs.sector1)[1]<-"Sector"
committments2 <- aggregate(x=bs$Comulative.Commitment,
          by=list(bs$AMP.Sector,bs$Project.ID),
          FUN=mean)
bs.sector2 <- committments2 %>%                              
group_by(Group.1) %>%
summarise(total = sum(x, na.rm=T))
bs.sector2$share=round(bs.sector2$total/sum(bs.sector2$total)*100,1)
colnames(bs.sector2)[1]<-"Sector"
bs.sector1 <- merge(bs.sector1, bs.sector2)
colnames(bs.sector1) <- c("Sector", "BS_count","Total", "BS_Share")


dis.aid <- dataMalawi[dataMalawi$Precision==5 | dataMalawi$Precision==6, ]
dis.sector1 <- dis.aid %>%                              
group_by(AMP.Sector) %>%
summarise(count = n_distinct(Project.ID))
colnames(dis.sector1)[1]<-"Sector"
committments2 <- aggregate(x=dis.aid$Comulative.Commitment,
          by=list(dis.aid$AMP.Sector,dis.aid$Project.ID),
          FUN=mean)
dis.sector2 <- committments2 %>%                              
group_by(Group.1) %>%
summarise(total = sum(x, na.rm=T))
dis.sector2$share=round(dis.sector2$total/sum(dis.sector2$total)*100,1)
colnames(dis.sector2)[1]<-"Sector"
dis.sector1 <- merge(dis.sector1, dis.sector2)
colnames(dis.sector1) <- c("Sector", "DIS_count","Total", "DIS_Share")

sector <- merge(pr.sector1[,-3],merge(bs.sector1[,-3], dis.sector1[,-3]))
sector[,1] <- as.character(sector[,1])
sector <- rbind(c("", "Baseline","","Budget Support","", "Aggregated",""),sector)
xtable(sector)

pdf("sector.pdf", height=11, width=8.5)
grid.table(sector)
dev.off()
@

% Table with continous measure of projects

<<Continuous, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
# created in Malawi2021.r

dhs.urban <- dhs
dhs <- dhs[dhs$urban==0,]

dhs$genderind <- dhs$wattind
dhs[is.na(dhs$wattind), "genderind"] <- dhs[is.na(dhs$wattind), "mattind"]
d <- as.data.frame(cor(dhs[,c( "genderind", "empind", "agencyind")], use = "complete.obs"))
#d[is.na(d)] <- 0
index.mat <- data.frame(chol2inv(chol(d)))
dhs$index <- rowSums(t(apply(dhs[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))


#dhs$index2 <-rowMeans(dhs[,c("genderind", "empind", "agencyind")], na.rm=TRUE)

#dhs$index3 <-rowMeans(dhs[,c("genderind", "empind", "agencyind")])

robse <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 2]) }
robp <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 4]) }

HSbase <- felm(empind ~ Exposure10N*After , dhs)
HSbaseC <- felm(empind ~ Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase <- felm(agencyind ~ Exposure10N*After , dhs)
JbaseC <- felm(agencyind ~ Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase <- felm(wattind ~ Exposure10N*After , dhs)
WIbaseC <- felm(wattind ~ Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase <- felm(mattind ~ Exposure10N*After , dhs)
MIbaseC <- felm(mattind ~ Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase <- felm(index ~ Exposure10N*After , dhs)
IbaseC <- felm(index ~ Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


star.out.1 <- stargazer(HSbase, Jbase, WIbase,  MIbase,  Ibase,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbase), robse(Jbase), robse(WIbase), robse(MIbase), robse(Ibase)), 
         #p= list(robp(HSbase), robp(Jbase), robp(WIbase), robp(MIbase), robp(Ibase)), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, all aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:Replication",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          )

star.out.2 <- stargazer(HSbaseC, JbaseC, WIbaseC,  MIbaseC,  IbaseC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbaseC), robse(JbaseC), robse(WIbaseC), robse(MIbaseC), robse(IbaseC)), 
         #p= list(robp(HSbaseC), robp(JbaseC), robp(WIbaseC), robp(MIbaseC), robp(IbaseC)), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, and the number of aid projects at the district level. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )


@

 
<<ContinuousG, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  

HSbaseG <- felm(empind ~ Exposure10GN*After + Exposure10N*After , dhs)
HSbaseGC <- felm(empind ~ Exposure10GN*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
JbaseG <- felm(agencyind ~ Exposure10GN*After + Exposure10N*After , dhs)
JbaseGC <- felm(agencyind ~ Exposure10GN*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbaseG <- felm(wattind ~ Exposure10GN*After + Exposure10N*After , dhs)
WIbaseGC <- felm(wattind ~ Exposure10GN*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbaseG <- felm(mattind ~ Exposure10GN*After + Exposure10N*After , dhs)
MIbaseGC <- felm(mattind ~ Exposure10GN*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
IbaseG <- felm(index ~ Exposure10GN*After + Exposure10N*After , dhs)
IbaseGC <- felm(index ~ Exposure10GN*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)

star.out.1 <- stargazer(HSbaseG, JbaseG, WIbaseG,  MIbaseG,  IbaseG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, gender aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:Robustness_nodummy",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove")
          )

star.out.2 <- stargazer(HSbaseGC, JbaseGC, WIbaseGC,  MIbaseGC,  IbaseGC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@

% Pre-treat differences between matrilineal and patrilineal

<<nordiffPM, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=
# Normalized differences - Matri Patri
temp <- aggregate(dhs[, "matrilineal"], list(dhs$grid, dhs$DHSCLUST), mean)
colnames(temp) <- c("grid", "DHSCLUST", "sh.matri")
dhs <- merge(dhs, temp, by=c("grid", "DHSCLUST"), all=T)

#var <- c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "AgeBirth" "KnowModernContraceptive" "ParentViolence" "WomanEarnings" "WomanHusbandEarnings", "WomanHealthCare", "WomanPurchase" , "WomanFamilyVisit", "WomRefuseSex" , "WomReqCondom", "WomMoreChi" , "WomNoMoreChi", "WomanPurchaseS" , "WomanDailyPurchaseS" , "WomanFamilyVisitS", "WomanHealthCareS" , "OK2BeatWife", "index") 

treat <- (dhs[dhs$sh.matri>.73 & dhs$After==0, c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "AgeBirth", "KnowModernContraceptive", "ParentViolence", "WomanEarnings", "WomanHusbandEarnings", "WomanHealthCare", "WomanPurchase" , "WomanFamilyVisit", "WomRefuseSex" , "WomReqCondom", "WomMoreChi" , "WomNoMoreChi", "WomanPurchaseS" , "WomanDailyPurchaseS" , "WomanFamilyVisitS", "WomanHealthCareS" , "OK2BeatWife", "index")  ]) 
control <- (dhs[dhs$sh.matri<=.73 & dhs$After==0, c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "AgeBirth", "KnowModernContraceptive", "ParentViolence", "WomanEarnings", "WomanHusbandEarnings", "WomanHealthCare", "WomanPurchase" , "WomanFamilyVisit", "WomRefuseSex" , "WomReqCondom", "WomMoreChi" , "WomNoMoreChi", "WomanPurchaseS" , "WomanDailyPurchaseS" , "WomanFamilyVisitS", "WomanHealthCareS" , "OK2BeatWife", "index")  ])
data <-  (dhs[dhs$After==0 , c("HhdSize", "age", "muslim", "matrilineal",  "Exposure10N", "YearsEdu", "Literacy", "AgeBirth", "KnowModernContraceptive", "ParentViolence", "WomanEarnings", "WomanHusbandEarnings", "WomanHealthCare", "WomanPurchase" , "WomanFamilyVisit", "WomRefuseSex" , "WomReqCondom", "WomMoreChi" , "WomNoMoreChi", "WomanPurchaseS" , "WomanDailyPurchaseS" , "WomanFamilyVisitS", "WomanHealthCareS" , "OK2BeatWife", "index")  ])
sumstatT <- do.call(data.frame,
                    list(meant = apply(treat, 2, mean, na.rm = T),
                        sdt = apply(treat, 2, sd, na.rm = T),
                        meanc = apply(control, 2, mean, na.rm = T),
                        sdc = apply(control, 2, sd, na.rm = T)))
                        # ,
                        # nd= apply(data[,-1], 2, 
                        # function(x) ((mean(x[data$sh.matri>.73], na.rm=T)-mean(x[data$sh.matri<=.73], na.rm=T))/
                        #   ((sum((x[data$sh.matri>.73] - mean(x[data$sh.matri>.73], na.rm=T))^2, na.rm=T)/(nrow(treat)-1) +
                        #               sum((x[data$sh.matri<=.73] - mean(x[data$sh.matri<=.73], na.rm=T))^2, na.rm=T)/(nrow(control)-1))/2)^.5))))
                                                     
sumstatT$nd <- (sumstatT$meant-sumstatT$meanc)/((sumstatT$sdt^2+sumstatT$sdc^2)/2)^.5


table_nd <- xtable(sumstatT, auto = TRUE, booktabs=TRUE,  caption = "Normalized differences, matrilineal VS patrilineal", digit=2, include.rownames = FALSE, label='norrdiffPM')
colnames(table_nd)<-c("Mean Matri", "sd Matri", "Mean Patri", "sd Patri" ,"Nor Dif")

print(table_nd, floating = T, latex.environments = "center", table.placement="h")
#index
mean(data[data$After==1, "index"], na.rm=T)
mean(data[data$After==0, "index"], na.rm=T)
sum((data[data$After==1, "index"] - mean(data[data$After==1, "index"], na.rm=T))^2, na.rm=T)/nrow(treat)
sum((data[data$After==0, "index"] - mean(data[data$After==0, "index"], na.rm=T))^2, na.rm=T)/nrow(control)
(0.1770137-0.1437325)/(0.04122445+0.05380818)^.5
# 0.11
@

% Pre-treat differences between matrilineal and patrilineal, statistic
%https://cran.r-project.org/web/packages/compareGroups/vignettes/compareGroups_vignette.html




% Pre-trends 2000-2004 in matri vs patri
<<Baseprem2, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
dhs.pre.urban <- dhs.pre
dhs.pre <- dhs.pre[dhs.pre$urban==0,]

dhs.pre$Exposure <- 0
dhs.pre[dhs.pre$Exposure10N>0 & !is.na(dhs.pre$Exposure10N), "Exposure"] <- 1
dhs.pre[is.na(dhs.pre$Exposure10N), "Exposure"] <- NA

dhs.pre$genderind <- dhs.pre$wattind
dhs.pre[is.na(dhs.pre$wattind), "genderind"] <- dhs.pre[is.na(dhs.pre$wattind), "mattind"]

dhs.pre$index <- rowSums(t(apply(dhs.pre[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))

dhs.pre$grid <- interaction(dhs.pre$Latbins, dhs.pre$Longbins, sep = ":")
temp <- aggregate(dhs.pre[, "matrilineal"], list(dhs.pre$grid, dhs.pre$DHSCLUST), mean)
colnames(temp) <- c("grid", "DHSCLUST", "sh.matri")
dhs.pre <- merge(dhs.pre, temp, by=c("grid", "DHSCLUST"), all=T)

HSbasepre <- felm(empind ~ I(sh.matri>.73)*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
Jbasepre <- felm(agencyind ~ I(sh.matri>.73)*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
WIbasepre <- felm(wattind ~ I(sh.matri>.73)*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
MIbasepre <- felm(mattind ~ I(sh.matri>.73)*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs.pre)
Ibasepre <- felm(index ~ I(sh.matri>.73)*After+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid|0| DHSCLUST, dhs.pre)


stargazer(HSbasepre, Jbasepre, WIbasepre,  MIbasepre,  Ibasepre,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          
          #se= list(robse(HSbasepre), robse(Jbasepre), robse(WIbasepre), robse(MIbasepre), robse(Ibasepre)), 
         #p= list(robp(HSbasepre), robp(Jbasepre), robp(WIbasepre), robp(MIbasepre), robp(Ibasepre)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Pre-trends, matri VS patri",
          label = "tab:pretrendsMP",
          omit.stat = c("adj.rsq", "ser")
          #keep = c("\\Exposure\\", "After")
          #keep = c("Exposure", "After"),
          #covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

@


% Omitted variable bias

<<InterFE, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")
# created in Malawi2021.r

dhs.urban <- dhs
dhs <- dhs[dhs$urban==0,]

dhs$genderind <- dhs$wattind
dhs[is.na(dhs$wattind), "genderind"] <- dhs[is.na(dhs$wattind), "mattind"]
d <- as.data.frame(cor(dhs[,c( "genderind", "empind", "agencyind")], use = "complete.obs"))
#d[is.na(d)] <- 0
index.mat <- data.frame(chol2inv(chol(d)))
dhs$index <- rowSums(t(apply(dhs[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))


#dhs$index2 <-rowMeans(dhs[,c("genderind", "empind", "agencyind")], na.rm=TRUE)

#dhs$index3 <-rowMeans(dhs[,c("genderind", "empind", "agencyind")])

robse <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 2]) }
robp <- function(m, robust=T) { return(coef(summary(m, robust=T))[, 4]) }

HSbase <- felm(empind ~ I(Exposure10N>0)*After +After:district , dhs)
HSbaseC <- felm(empind ~ I(Exposure10N>0)*After +After:district+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Jbase <- felm(agencyind ~ I(Exposure10N>0)*After +After:district , dhs)
JbaseC <- felm(agencyind ~ I(Exposure10N>0)*After +After:district+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbase <- felm(wattind ~ I(Exposure10N>0)*After +After:district , dhs)
WIbaseC <- felm(wattind ~ I(Exposure10N>0)*After +After:district+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbase <- felm(mattind ~ I(Exposure10N>0)*After +After:district , dhs)
MIbaseC <- felm(mattind ~ I(Exposure10N>0)*After +After:district+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
Ibase <- felm(index ~ I(Exposure10N>0)*After +After:district , dhs)
IbaseC <- felm(index ~ I(Exposure10N>0)*After +After:district+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)


star.out.1 <- stargazer(HSbase, Jbase, WIbase,  MIbase,  Ibase,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbase), robse(Jbase), robse(WIbase), robse(MIbase), robse(Ibase)), 
         #p= list(robp(HSbase), robp(Jbase), robp(WIbase), robp(MIbase), robp(Ibase)), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "District by After FE", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:Replication",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10N\\b", "After"),
          #omit= c( 5:length(coef(HSbase))),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          )

star.out.2 <- stargazer(HSbaseC, JbaseC, WIbaseC,  MIbaseC,  IbaseC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
         #se= list(robse(HSbaseC), robse(JbaseC), robse(WIbaseC), robse(MIbaseC), robse(IbaseC)), 
         #p= list(robp(HSbaseC), robp(JbaseC), robp(WIbaseC), robp(MIbaseC), robp(IbaseC)), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, and the number of aid projects at the district level. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )


@

 
<<InterFEG, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  

HSbaseG <- felm(empind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After , dhs)
HSbaseGC <- felm(empind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
JbaseG <- felm(agencyind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After , dhs)
JbaseGC <- felm(agencyind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
WIbaseG <- felm(wattind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After , dhs)
WIbaseGC <- felm(wattind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
MIbaseG <- felm(mattind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After , dhs)
MIbaseGC <- felm(mattind ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)
IbaseG <- felm(index ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After , dhs)
IbaseGC <- felm(index ~ I(Exposure10GN>0)*After +After:district + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs)

star.out.1 <- stargazer(HSbaseG, JbaseG, WIbaseG,  MIbaseG,  IbaseG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          title     = "Impact on women's status indices, gender aid", 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: Unconditional",
          label = "tab:gender",
          omit.stat = c("adj.rsq", "ser"), 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove")
          )

star.out.2 <- stargazer(HSbaseGC, JbaseGC, WIbaseGC,  MIbaseGC,  IbaseGC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          dep.var.caption  = "Panel B: Conditional",
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.stat = c("adj.rsq", "ser"),
          notes        = "\\parbox[t]{.7\\textwidth}{Exposure is measured within a 10 km radius. HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Conditional results control for a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004, "index"], na.rm=T),3)))
          )

@

% Median rather than mean for matri

<<MatriNewM, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")

dhs.urban <- dhs
dhs <- dhs[dhs$urban==0,]

dhs$genderind <- dhs$wattind
dhs[is.na(dhs$wattind), "genderind"] <- dhs[is.na(dhs$wattind), "mattind"]
d <- as.data.frame(cor(dhs[,c( "genderind", "empind", "agencyind")], use = "complete.obs"))
#d[is.na(d)] <- 0
index.mat <- data.frame(chol2inv(chol(d)))
dhs$index <- rowSums(t(apply(dhs[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))

temp <- aggregate(dhs[, "matrilineal"], list(dhs$grid, dhs$DHSCLUST), mean)
colnames(temp) <- c("grid", "DHSCLUST", "sh.matri")
dhs <- merge(dhs, temp, by=c("grid", "DHSCLUST"), all=T)

HSMatri <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
JMatri <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
WIMatri <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
MIMatri <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
IMatri <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)

HSMatriG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
JMatriG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
WIMatriG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
MIMatriG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)
IMatriG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri>.93)

stargazer(HSMatri, JMatri, WIMatri,  MIMatri,  IMatri,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"), 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact in matrilineal areas",
          label = "tab:Matri",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

stargazer(HSMatriG, JMatriG, WIMatriG,  MIMatriG,  IMatriG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE,
          omit.stat = c("adj.rsq", "ser"),
          dep.var.caption  = "Panel B: Gender aid",
          notes        = "\\parbox[t]{.85\\textwidth}{Exposure is measured within a 10 km radius. Ethnic groups classified as matrilineal are: Chewa, Lomwe, Yao, Ngoni, and Nyanja, based on Ibik (1970). HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri>.93, "index"], na.rm=T),3)))
          )

@

 <<PatriNewM, echo=FALSE, warning=FALSE, message=FALSE, results='asis'>>=  
load("/Users/Mema 1/Dropbox/AidDataGender/2021 March revisions/data/Malawi2021.RData")

dhs.urban <- dhs
dhs <- dhs[dhs$urban==0,]

dhs$genderind <- dhs$wattind
dhs[is.na(dhs$wattind), "genderind"] <- dhs[is.na(dhs$wattind), "mattind"]
d <- as.data.frame(cor(dhs[,c( "genderind", "empind", "agencyind")], use = "complete.obs"))
#d[is.na(d)] <- 0
index.mat <- data.frame(chol2inv(chol(d)))
dhs$index <- rowSums(t(apply(dhs[,c("genderind", "empind", "agencyind")], 1, function(x) rowSums(index.mat)*x)))/sum(rowSums(index.mat))

temp <- aggregate(dhs[, "matrilineal"], list(dhs$grid, dhs$DHSCLUST), mean)
colnames(temp) <- c("grid", "DHSCLUST", "sh.matri")
dhs <- merge(dhs, temp, by=c("grid", "DHSCLUST"), all=T)

HSPatri <- felm(empind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
JPatri <- felm(agencyind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
WIPatriC <- felm(wattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
MIPatriC <- felm(mattind ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
IPatriC <- felm(index ~ I(Exposure10N>0)*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)

HSPatriG <- felm(empind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
JPatriG <- felm(agencyind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
WIPatriG <- felm(wattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
MIPatriG <- felm(mattind ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)
IPatriG <- felm(index ~ I(Exposure10GN>0)*After + Exposure10N*After+distint+HhdSize+age+muslim+matrilineal+YearsEdu+Literacy |grid |0 | DHSCLUST, dhs, subset=sh.matri<=.93)

stargazer(HSPatri, JPatri, WIPatriC,  MIPatriC,  IPatriC,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          
          #se= list(robse(HSPatri), robse(JPatri), robse(WIPatriC), robse(MIPatriC), robse(IPatriC)), 
         #p= list(robp(HSPatri), robp(JPatri), robp(WIPatriC), robp(MIPatriC), robp(IPatriC)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE, 
          omit.table.layout = "n",
          dep.var.caption  = "Panel A: All aid", 
          title     = "Impact in patrilineal areas",
          label = "tab:Patri",
          omit.stat = c("adj.rsq", "ser"),
          keep = c("\\Exposure10N\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure")
          ) 

stargazer(HSPatriG, JPatriG, WIPatriG,  MIPatriG,  IPatriG,
          column.labels   = c("HS", "JBC", "WA", "MA", "Index"),
          #se= list(robse(HSPatriG), robse(JPatriG), robse(WIPatriG), robse(MIPatriG), robse(IPatriG)), 
         #p= list(robp(HSPatriG), robp(JPatriG), robp(WIPatriG), robp(MIPatriG), robp(IPatriG)),
          #align=TRUE, 
          dep.var.labels.include = FALSE,
          model.numbers = FALSE, df=FALSE, float=TRUE,
          omit.stat = c("adj.rsq", "ser"),
          dep.var.caption  = "Panel B: Gender aid",
          notes        = "\\parbox[t]{.85\\textwidth}{Exposure is measured within a 10 km radius. Ethnic groups classified as matrilineal are: Chewa, Lomwe, Yao, Ngoni, and Nyanja, based on Ibik (1970). HS is the \\cite{haushofer2016short} empowerment index, JBC is the \\cite{jayachandran2021using} agency index, WA and MA are indices of woomen's and men's attitudes in the sexual and reproductive sphere, Index is the aggregate of the previous four. Controls include a geographic FE, household size, respondent's age and ethnicity, dummy for muslim and urban, the number of aid projects at the district level, and an indicator for general aid within the radius in panel B. Standard errors clustered at the DHS cluster level in parentheses.}", 
          keep = c("\\Exposure10GN\\b", "After"),
          covariate.labels=c("Exposure", NA, "After:Exposure", "Remove"),
          add.lines = list(c("Mean", round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "empind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "agencyind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "wattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "mattind"], na.rm=T),3), round(median(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "index"], na.rm=T),3)),
            c("sd", round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "empind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "agencyind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "wattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "mattind"], na.rm=T),3), round(sd(dhs[dhs$Year==2004 & dhs$sh.matri<=.93, "index"], na.rm=T),3)))
          )

@


\end{document}
